#!/bin/bash

echo "========================================"
echo "   AiMenu 智能点餐系统 - 前端启动"
echo "========================================"
echo

echo "正在检查Node.js环境..."
if ! command -v node &> /dev/null; then
    echo "❌ 错误: 未检测到Node.js，请先安装Node.js"
    echo "下载地址: https://nodejs.org/"
    exit 1
fi

echo "✅ Node.js环境正常"

echo
echo "正在检查依赖包..."
if [ ! -d "node_modules" ]; then
    echo "📦 首次运行，正在安装依赖包..."
    npm install
    if [ $? -ne 0 ]; then
        echo "❌ 依赖安装失败，请检查网络连接"
        exit 1
    fi
    echo "✅ 依赖安装完成"
else
    echo "✅ 依赖包已存在"
fi

echo
echo "🚀 正在启动开发服务器..."
echo "📝 前端地址: http://localhost:3000"
echo "📝 确保后端API运行在: http://localhost:8000"
echo
echo "按 Ctrl+C 停止服务"
echo "========================================"
echo

npm run dev
